﻿using MediatR;
using RedDragon.Common.Domain.produceplan;
using RedDragon.Common.Infrastructure.Interface;
using T.Common.Domain.Common;

namespace RedDragon.RBAC.API.Application.Common.produceplanW
{
    public class produceplanCreateHandler : IRequestHandler<produceplanCreateCommon, Result>
    {
        public readonly IBaseRepository<produceplan> produceplanRepository;

        public produceplanCreateHandler(IBaseRepository<produceplan> produceplanRepository)
        {
            this.produceplanRepository = produceplanRepository;
        }

        public async Task<Result> Handle(produceplanCreateCommon request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = 0, Msg = "主生产计划新增失败" };
            try
            {
                var res = new produceplan()
                {
                    produceplanNumber = request.produceplanNumber,
                    produceplanName = request.produceplanName,
                    produceplanDetail = request.produceplanDetail,
                    produceplanStatus = request.produceplanStatus,
                    MakeName = request.MakeName,
                    MakeDepartment = request.MakeDepartment,
                    CreateTime = DateTime.Now,
                    produceplanAudit = 0
                };
                var res1 = await produceplanRepository.Add(res);
                if (res1 != 0)
                {
                    result.Code = 1;
                    result.Msg = "主生产计划新增成功";
                }



            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
